////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                            //
//                                                         WNProject                                                          //
//                                                                                                                            //
//            This file is distributed under the BSD 2-Clause open source license. See License.txt for details.               //
//                                                                                                                            //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "WNMemory/inc/WNMemory.h"
#include "WNMath/inc/WNRay2.h"
#include "WNMath/inc/WNLine2.h"
#include "WNMath/inc/WNLine3.h"

using namespace WNMath;
using namespace WNMemory;

// Constructors ////////////////////////////////////////////////////////////////////////////////////

WNRay2::WNRay2() :
    location(0.0f, 0.0f),
    direction(0.0f, 0.0f) {
}

WNRay2::WNRay2(const WN_FLOAT32* _f) :
    location(_f[0], _f[1]),
    direction(_f[2], _f[3]) {
}

WNRay2::WNRay2(const WNPoint2& _location, const WNVector2& _direction) :
    location(_location),
    direction(_direction) {
}

// Operators ///////////////////////////////////////////////////////////////////////////////////////

WNRay2 WNRay2::operator + () const {
    return(*this);
}

WNRay2 WNRay2::operator - () const {
    return(WNRay2(-location, -direction));
}

WN_BOOL WNRay2::operator == (const WNRay2& _ray) const {
    return(0 == WNMemCmp(this, &_ray, sizeof(WNRay2)));
}

WN_BOOL WNRay2::operator != (const WNRay2& _ray) const {
    return(0 != WNMemCmp(this, &_ray, sizeof(WNRay2)));
}

// Members /////////////////////////////////////////////////////////////////////////////////////////

WN_VOID WNRay2::Zero() {
    location.Zero();
    direction.Zero();
}

WN_VOID WNRay2::Set(const WN_FLOAT32* _f) {
    location.x = _f[0];
    location.y = _f[1];

    direction.x = _f[2];
    direction.y = _f[3];
}

WN_VOID WNRay2::Set(const WNPoint2& _location, const WNVector2& _direction) {
    location = _location;
    direction = _direction;
}

WNLine2 WNRay2::ToLine2() const {
    return(WNLine2(location, location + direction));
}

WNLine3 WNRay2::ToLine3() const {
    return(WNLine3(location.ToPoint3(), (location + direction).ToPoint3()));
}